package com.weiwei.diancan.view;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.weiwei.diancan.R;


/**
 * Created by BMW on 2016/10/18.
 */
public class PayPopwindow extends PopupWindow implements View.OnClickListener{

    private final View conentView;
    private final TextView tv_banka;
    private final TextView tv_mingxi;
    private final TextView tv_quanxian;
    private Activity context;
    private OnItemClick onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public PayPopwindow(Activity context){
        this.context = context;
        conentView = LayoutInflater.from(context).inflate(R.layout.pop_pay,null);
        tv_banka = (TextView)conentView.findViewById(R.id.tv_banka);
        tv_mingxi = (TextView)conentView.findViewById(R.id.tv_mingxi);
        tv_quanxian = (TextView)conentView.findViewById(R.id.tv_quanxian);
        tv_banka.setOnClickListener(this);
        tv_mingxi.setOnClickListener(this);
        tv_quanxian.setOnClickListener(this);

        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.beijingkuang));
        this.setFocusable(true);
        this.setOutsideTouchable(false);
    }

    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            //this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);
            this.showAsDropDown(parent,5,0);
        } else {
            this.dismiss();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_banka:
                onItemClick.onClick(0);
                break;
            case R.id.tv_mingxi:
                onItemClick.onClick(1);
                break;
            case R.id.tv_quanxian:
                onItemClick.onClick(2);
                break;
        }
    }

    public interface OnItemClick{
        void onClick(int index);
    }
}
